package ifosup.julien;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

public class IOtext {

	public static void lireEcrire() {
		File repertoire = new File("C:/Users/STAGIAIRE6/Documents/test");

		File fichierTexte = new File(repertoire, "test.txt");

		try {
			FileOutputStream fichierStream = new FileOutputStream(fichierTexte);
			fichierStream.write("Hello World!".getBytes());
			fichierStream.close();

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}// try-catch

		try {
			FileReader fichierReader = new FileReader(fichierTexte);
			BufferedReader buffer = new BufferedReader(fichierReader);
			boolean finBuffer = false;
			while (!finBuffer) {
				String ligne = buffer.readLine();
				finBuffer = (ligne == null);
				if (!finBuffer) {
					System.out.println(ligne);
				}
			}// while
			buffer.close();
			fichierReader.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}// try-catch
	}
}
